package com.fast.commons.utils.mail;

import com.fast.commons.utils.PropertyUtils;

/**
 * 说明：单例模式，加载配置信息
 * #邮件发送服务器、端口、验证
 * mail.smtp.host=mail.whizen.com
 * mail.smtp.port=25
 * mail.smtp.auth=true
 * mail.smtp.protocol=smtp

 * #邮件接收服务器，端口
 * mail.pop3.host=mail.whizen.com
 * mail.pop3.port=110
 * mail.pop3.protocol=pop3

 * #设置默认的发件人信息
 * mail.from=yanghaoquan@whizen.com
 * mail.username=yanghaoquan@whizen.com
 * mail.password=yhqmcq520+
 * mail.aliasname=\u6D4B\u8BD5Dawn\u90AE\u4EF6\u53D1\u9001\u529F\u80FD
 * mail.subject=\u6D4B\u8BD5Dawn\u90AE\u4EF6\u53D1\u9001\u529F\u80FD
 * <br/>作者：杨浩泉
 * <br/>日期：2009-10-1
 */
public class MailConfiguraton {
	
	private String mailSMTPHost ;			/** 缺省的主机名称 */
	
	private String mailSMTPPort ;			/** 缺省的SMTP端口号 */
	
	private String mailPOP3Host ;			/** 缺省的主机名称 */
	
	private String mailPOP3Port ;			/** 缺省的POP3端口号 */
	
	private String mailPOP3Protocol ;		/** 邮箱连接协议 */
	
	private String mailAuth ;				/** 是否需要验证 */
	
	private String mailAliasName ;			/** 是否需要验证 */
	
	private String mailFromAdmin ;			/** 缺省为管理员发送人地址 */
	
	private String userNameAdmin ;			/** 缺省为管理员发送人的邮箱账号 */
	
	private String passWordAdmin ;			/** 缺省为管理员发送人的邮箱密码 */
	
	private String defaulSubject ;			/** 缺省的邮件主题 */
	
	private static MailConfiguraton intance = null ; /** 加载属性文件中的SMTP信息 */
	
	public static MailConfiguraton getInstance() {
		if(null == intance) {
			intance = new MailConfiguraton() ;
			return intance ;
		} else {
			return intance ;
		}
	}
	
	private MailConfiguraton() {
		this.setMailSMTPHost(PropertyUtils.getValue("mail.smtp.host")) ;
		this.setMailSMTPPort(PropertyUtils.getValue("mail.smtp.port")) ;
		this.setMailPOP3Host( PropertyUtils.getValue("mail.pop3.host")) ;
		this.setMailPOP3Port(PropertyUtils.getValue("mail.pop3.port")) ;
		this.setMailPOP3Protocol(PropertyUtils.getValue("mail.pop3.protocol")) ;
		this.setMailAuth(PropertyUtils.getValue("mail.smtp.auth")) ;
		this.setMailAliasName((null == PropertyUtils.getValue("mail.aliasname") || "".equals(PropertyUtils.getValue("mail.aliasname"))?"":PropertyUtils.getValue("mail.aliasname"))) ;
		this.setMailFromAdmin(PropertyUtils.getValue("mail.from")) ;
		this.setUserNameAdmin((null == PropertyUtils.getValue("mail.username") || "".equals(PropertyUtils.getValue("mail.username"))?null:PropertyUtils.getValue("mail.username"))) ;
		this.setPassWordAdmin((null == PropertyUtils.getValue("mail.password") || "".equals(PropertyUtils.getValue("mail.password"))?null:PropertyUtils.getValue("mail.password"))) ;
		this.setDefaulSubject(((null == PropertyUtils.getValue("mail.subject") || "".equals(PropertyUtils.getValue("mail.subject"))?null:PropertyUtils.getValue("mail.subject")))) ;
	}

	/** 获取邮箱域名 */
	public static String getEmailDomain() {
		String domain = PropertyUtils.getValue("mail.smtp.host") ;
		return "@"+domain.substring(domain.indexOf(".")+1, domain.length()) ; 
	}
	
	public String getDefaulSubject() {
		return defaulSubject;
	}

	public void setDefaulSubject(String defaulSubject) {
		this.defaulSubject = defaulSubject;
	}

	public String getMailSMTPHost() {
		return mailSMTPHost;
	}

	public void setMailSMTPHost(String mailSMTPHost) {
		this.mailSMTPHost = mailSMTPHost;
	}

	public String getMailSMTPPort() {
		return mailSMTPPort;
	}

	public String getMailAliasName() {
		return mailAliasName;
	}

	public void setMailAliasName(String mailAliasName) {
		this.mailAliasName = mailAliasName;
	}

	public void setMailSMTPPort(String mailSMTPPort) {
		this.mailSMTPPort = mailSMTPPort;
	}

	public String getMailPOP3Host() {
		return mailPOP3Host;
	}

	public void setMailPOP3Host(String mailPOP3Host) {
		this.mailPOP3Host = mailPOP3Host;
	}

	public String getMailPOP3Port() {
		return mailPOP3Port;
	}

	public void setMailPOP3Port(String mailPOP3Port) {
		this.mailPOP3Port = mailPOP3Port;
	}

	public String getMailPOP3Protocol() {
		return mailPOP3Protocol;
	}

	public void setMailPOP3Protocol(String mailPOP3Protocol) {
		this.mailPOP3Protocol = mailPOP3Protocol;
	}

	public String getMailAuth() {
		return mailAuth;
	}

	public void setMailAuth(String mailAuth) {
		this.mailAuth = mailAuth;
	}

	public String getMailFromAdmin() {
		return mailFromAdmin;
	}

	public void setMailFromAdmin(String mailFromAdmin) {
		this.mailFromAdmin = mailFromAdmin;
	}

	public String getUserNameAdmin() {
		return userNameAdmin;
	}

	public void setUserNameAdmin(String userNameAdmin) {
		this.userNameAdmin = userNameAdmin;
	}

	public String getPassWordAdmin() {
		return passWordAdmin;
	}

	public void setPassWordAdmin(String passWordAdmin) {
		this.passWordAdmin = passWordAdmin;
	}

}
